package com.android.lmy.BroadcastReceiver;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.android.lmy.R;
import com.jeremyliao.liveeventbus.LiveEventBus;

import java.util.Calendar;

public class BroadcastReceiverActivity extends AppCompatActivity implements View.OnClickListener {
    private Button button1;
    private TextView tvText;

    private Button button2;
    private Button button3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broadcast_receiver);
        button1 = findViewById(R.id.button1);
        tvText = findViewById(R.id.tv_text);
        button2 = findViewById(R.id.button2);
        button3 = findViewById(R.id.button3);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button1:
                Intent intent = new Intent("com.android.contentprovidersqlb");
                intent.setComponent(new ComponentName("com.android.contentprovidersqlb", "com.android.contentprovidersqlb.ReceiveBroadCast"));
                sendBroadcast(intent);
                break;
            case R.id.button2:
                //只需要指定指定的广播接受的绝对路径即可
                Intent intent2 = new Intent("com.android.contentprovidersqlb");
                intent2.setComponent(new ComponentName("com.android.contentprovidersqlb", "com.android.contentprovidersqlb.ReceiveBroadCast2"));
                sendBroadcast(intent2);
                break;
            case R.id.button3:
                LiveEventBus
                        .get("key_name")
                        .broadcast("KKKKKK");
                break;
        }
    }
}
